package com.jaya.budan.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jaya.budan.R;
import com.jaya.budan.adapter.CommentExpandAdapter;
import com.jaya.budan.adapter.GV_Recharge_Item_Adapter;
import com.jaya.budan.adapter.GeRen_Main_Fans_ListView_Adapter;
import com.jaya.budan.adapter.Photo_Album_Adapter;
import com.jaya.budan.base.BaseActivity;
import com.jaya.budan.bean.ListUser_Information;
import com.jaya.budan.bean.User_Limit;
import com.jaya.budan.bean.User_Wallet;
import com.jaya.budan.connect.RequestConnect;
import com.jaya.budan.utils.ToolUtils;
import com.jaya.budan.utils.VolleyUtil;
import com.jaya.budan.views.Circle_ImageView;
import com.jaya.budan.views.CommentExpandableListView;
import com.jaya.budan.views.CommonPopWindow;
import com.jaya.budan.views.HorizontalListView;
import com.jaya.budan.views.MyGridView;
import com.jaya.budan.views.MyListView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.List;

public class Square_Detail_Activity extends BaseActivity implements View.OnClickListener, CommonPopWindow.ViewClickListener {

    private RelativeLayout back;
    private LinearLayout ll_square_dianzan, ll_square_detail;
    private String access_token, bd_money, s_id, type;
    private List<ListUser_Information> user_informations;
    private TextView tv_nearby_listview_item_name, tv_nearby_listview_item_distance, tv_nearby_listview_item_content, tv_nearby_listview_item_look, tv_geren_main_dianzan, tv_geren_main_pinglun, tv_geren_main_zhichi;
    private Button btn_gerentg_tgjl, btn_gerentg_ddjl, btn_gerentg_zhichi, btn_chat_send_mes;
    private MyGridView gv_square_nearby;
    private MyListView lv_xyf_jilu;
    private CommentExpandableListView lv_square_detail;
    private ImageView iv_nearby_item_isvip, iv_square_dianzan, iv_square_care, iv_square_diandian;
    private Circle_ImageView iv_nearby_item_icon;
    private HorizontalListView main_hlv_vip;
    private EditText et_chat;
    private int roomId, to_uid;
    private List<User_Wallet> mlist;
    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_square_detail);
        Intent intent = getIntent();
        access_token = intent.getStringExtra("access_token");
        roomId = intent.getIntExtra("roomId", 0);
        user_informations = (List<ListUser_Information>) intent.getSerializableExtra("user_information");
        back = findViewById(R.id.back);
        iv_nearby_item_icon = findViewById(R.id.iv_nearby_item_icon);
        iv_nearby_item_isvip = findViewById(R.id.iv_nearby_item_isvip);
        iv_square_dianzan = findViewById(R.id.iv_square_dianzan);
        iv_square_care = findViewById(R.id.iv_square_care);
        iv_square_diandian = findViewById(R.id.iv_square_diandian);
        main_hlv_vip = findViewById(R.id.main_hlv_vip);
        ll_square_dianzan = findViewById(R.id.ll_square_dianzan);
        ll_square_detail = findViewById(R.id.ll_square_detail);
        tv_nearby_listview_item_name = findViewById(R.id.tv_nearby_listview_item_name);
        tv_nearby_listview_item_distance = findViewById(R.id.tv_nearby_listview_item_distance);
        tv_nearby_listview_item_content = findViewById(R.id.tv_nearby_listview_item_content);
        tv_nearby_listview_item_look = findViewById(R.id.tv_nearby_listview_item_look);
        tv_geren_main_dianzan = findViewById(R.id.tv_geren_main_dianzan);
        tv_geren_main_pinglun = findViewById(R.id.tv_geren_main_pinglun);
        tv_geren_main_zhichi = findViewById(R.id.tv_geren_main_zhichi);
        gv_square_nearby = findViewById(R.id.gv_square_nearby);
        btn_gerentg_tgjl = findViewById(R.id.btn_gerentg_tgjl);
        btn_gerentg_ddjl = findViewById(R.id.btn_gerentg_ddjl);
        btn_gerentg_zhichi = findViewById(R.id.btn_gerentg_zhichi);
        btn_chat_send_mes = findViewById(R.id.btn_chat_send_mes);
        et_chat = findViewById(R.id.et_chat);
        lv_square_detail = findViewById(R.id.lv_square_detail);
        lv_xyf_jilu = findViewById(R.id.lv_xyf_jilu);
        back.setOnClickListener(this);
        btn_gerentg_tgjl.setOnClickListener(this);
        btn_gerentg_ddjl.setOnClickListener(this);
        btn_gerentg_zhichi.setOnClickListener(this);
        btn_chat_send_mes.setOnClickListener(this);
        ll_square_dianzan.setOnClickListener(this);
        iv_square_care.setOnClickListener(this);
        iv_square_diandian.setOnClickListener(this);
        tv_geren_main_zhichi.setOnClickListener(this);
        tv_nearby_listview_item_name.setText("" + user_informations.get(roomId).getNicename());
        tv_nearby_listview_item_distance.setText("" + user_informations.get(roomId).getDistance() + " | " + user_informations.get(roomId).getCreate_at());
        tv_nearby_listview_item_content.setText("" + user_informations.get(roomId).getContent());
        if (ToolUtils.isEmpty(user_informations.get(roomId).getAddress())){
            tv_nearby_listview_item_look.setVisibility(View.GONE);
        } else {
            tv_nearby_listview_item_look.setVisibility(View.VISIBLE);
            tv_nearby_listview_item_look.setText("" + user_informations.get(roomId).getAddress());
        }
        tv_geren_main_dianzan.setText("" + user_informations.get(roomId).getComment_count());
        tv_geren_main_pinglun.setText("" + user_informations.get(roomId).getShare());
        btn_gerentg_tgjl.setText("赞   " + user_informations.get(roomId).getComment_count());
        btn_gerentg_ddjl.setText("评论 " + user_informations.get(roomId).getShare());
        btn_gerentg_zhichi.setText("支持 " + user_informations.get(roomId).getLook());
//        user_informations.get(roomId).getFiles().get(roomId).getPath();
        Glide.with(this).load(user_informations.get(roomId).getHead_path() + "").apply(new RequestOptions()
                .placeholder(R.mipmap.bd_circle_logo).error(R.mipmap.bd_circle_logo)
                .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
        ).into(iv_nearby_item_icon);
        gv_square_nearby.setHorizontalSpacing(15);
        gv_square_nearby.setVerticalSpacing(15);
        gv_square_nearby.setAdapter(new Photo_Album_Adapter(this, null, user_informations.get(roomId).getFiles(), null, 1));
        gv_square_nearby.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //图片点击放大
//                CommonPopWindow.newBuilder()
//                        .setView(R.layout.pop_square_detail)
//                        .setAnimationStyle(R.style.AnimUp)
//                        .setBackgroundDrawable(new BitmapDrawable())
//                        .setSize(0, 1800)
//                        .setViewOnClickListener(Square_Detail_Activity.this)
//                        .setBackgroundDarkEnable(true)
//                        .setOutsideTouchable(false)
//                        .setBackgroundAlpha(0.0f)
//                        .build(Square_Detail_Activity.this)
//                        .showAsCenter(view);
                Intent intent = new Intent(Square_Detail_Activity.this, Square_Detail_Photo_Activity.class);
                intent.putExtra("access_token", access_token);
                intent.putExtra("roomId", position);
                intent.putExtra("user_information", (Serializable) user_informations);
                startActivity(intent);
            }
        });
        tv_geren_main_dianzan.setSelected(true);
//        if (mlist.get(position).getIs_vip() == 1){
//            iv_nearby_item_isvip.setVisibility(View.VISIBLE);//是 会员
//        } else {
//            iv_nearby_item_isvip.setVisibility(View.INVISIBLE);
//        }
//        // 获取屏幕宽高
//        int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); // 屏幕宽（像素，如：480px）
//        HorizontalListViewAdapter horizontalListViewAdapter = new HorizontalListViewAdapter(mcontext, screenWidth, mlist);
//        main_hlv_vip.setAdapter(horizontalListViewAdapter);
        btn_gerentg_tgjl.setBackgroundResource(R.drawable.login_login);
        btn_gerentg_ddjl.setBackgroundResource(R.drawable.login_exit);
        btn_gerentg_zhichi.setBackgroundResource(R.drawable.login_exit);
        lv_xyf_jilu.setVisibility(View.VISIBLE);
        lv_square_detail.setVisibility(View.GONE);
        ll_square_detail.setVisibility(View.GONE);
        postGetDZlistData();
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            case R.id.ll_square_dianzan:
                if (tv_geren_main_dianzan.isSelected()){
                    tv_geren_main_dianzan.setSelected(false);
                    type = "1";
                    iv_square_dianzan.setImageResource(R.mipmap.iv_dianzan_yes);
                } else {
                    tv_geren_main_dianzan.setSelected(true);
                    type = "2";
                    iv_square_dianzan.setImageResource(R.mipmap.iv_dianzan_no);
                }
                JSONObject object = new JSONObject();
                try {
                    object.put("type", type);//1点赞 2取消点赞
                    object.put("s_id", user_informations.get(roomId).getFiles().get(0).getS_id());
                    object.put("s_com_id", "");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                postData(object);
                break;
            case R.id.iv_square_care:
                JSONObject object1 = new JSONObject();
                try {
                    object1.put("uid", user_informations.get(roomId).getUid());
                    object1.put("type", 1);//1 关注 2取消关注
                    object1.put("flag", 1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                postUserFansData(object1, iv_square_care);
                break;
            case R.id.iv_square_diandian:
                CommonPopWindow.newBuilder()
                        .setView(R.layout.pop_geren_diandian)
                        .setAnimationStyle(R.style.AnimUp)
                        .setBackgroundDrawable(new BitmapDrawable())
                        .setSize(0, 400)
                        .setViewOnClickListener(this)
                        .setBackgroundDarkEnable(true)
                        .setOutsideTouchable(false)
                        .setBackgroundAlpha(0.7f)
                        .build(Square_Detail_Activity.this)
                        .showAsBottom(v);
                break;
            case R.id.tv_geren_main_zhichi:
                postZhiChiData(v);
                break;
            case R.id.btn_gerentg_tgjl:
                btn_gerentg_tgjl.setBackgroundResource(R.drawable.login_login);
                btn_gerentg_ddjl.setBackgroundResource(R.drawable.login_exit);
                btn_gerentg_zhichi.setBackgroundResource(R.drawable.login_exit);
                lv_xyf_jilu.setVisibility(View.VISIBLE);
                lv_square_detail.setVisibility(View.GONE);
                ll_square_detail.setVisibility(View.GONE);
                postGetDZlistData();
                break;
            case R.id.btn_gerentg_ddjl:
                btn_gerentg_tgjl.setBackgroundResource(R.drawable.login_exit);
                btn_gerentg_ddjl.setBackgroundResource(R.drawable.login_login);
                btn_gerentg_zhichi.setBackgroundResource(R.drawable.login_exit);
                lv_xyf_jilu.setVisibility(View.GONE);
                lv_square_detail.setVisibility(View.VISIBLE);
                ll_square_detail.setVisibility(View.VISIBLE);
                postGetPLlistData();
                break;
            case R.id.btn_gerentg_zhichi:
                btn_gerentg_tgjl.setBackgroundResource(R.drawable.login_exit);
                btn_gerentg_ddjl.setBackgroundResource(R.drawable.login_exit);
                btn_gerentg_zhichi.setBackgroundResource(R.drawable.login_login);
                lv_xyf_jilu.setVisibility(View.VISIBLE);
                lv_square_detail.setVisibility(View.GONE);
                ll_square_detail.setVisibility(View.GONE);
                postZhiChiData();
                break;
            case R.id.btn_chat_send_mes:
                JSONObject object2 = new JSONObject();
                try {
                    object2.put("s_id", user_informations.get(roomId).getFiles().get(0).getS_id());
                    object2.put("c_id", 0);//回复评论所在的一级评论id 如果是一级评论则为0
                    object2.put("p_id", 1);//被回复的评论id
                    object2.put("to_uid", to_uid);//被回复人的uid
                    object2.put("content", et_chat.getText().toString().trim());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                postSendPLData(object2);
                break;
            default:
                break;
        }
    }

    @SuppressLint({"NonConstantResourceId", "SetTextI18n"})
    @Override
    public void getChildView(final PopupWindow mPopupWindow, View view, int mLayoutResId) {
        switch (mLayoutResId) {
            case R.layout.pop_square_detail_pay:
                GridView gv_pop_pay = view.findViewById(R.id.gv_pop_pay);
                Circle_ImageView civ_pop_square = view.findViewById(R.id.civ_pop_square);
                TextView tv_vip_zx_title = view.findViewById(R.id.tv_vip_zx_title);
                ImageView tv_vip_zx_price = view.findViewById(R.id.tv_vip_zx_price);
                Button btn_login = view.findViewById(R.id.btn_login);
                Glide.with(this).load(user_informations.get(roomId).getHead_path() + "").apply(new RequestOptions()
                        .placeholder(R.mipmap.bd_circle_logo).error(R.mipmap.bd_circle_logo)
                        .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
                ).into(civ_pop_square);
                tv_vip_zx_title.setText("" + user_informations.get(roomId).getNicename());
//                if (user_informations.get(roomId).getIs_vip() == 1){
//                    tv_vip_zx_price.setVisibility(View.VISIBLE);//是 会员
//                } else {
//                    tv_vip_zx_price.setVisibility(View.INVISIBLE);
//                }
                gv_pop_pay.setVerticalSpacing(20);
                gv_pop_pay.setHorizontalSpacing(20);
                GV_Recharge_Item_Adapter adapter = new GV_Recharge_Item_Adapter(Square_Detail_Activity.this, mlist, 0);
                gv_pop_pay.setAdapter(adapter);
                gv_pop_pay.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        adapter.setSelect(position);
                        adapter.notifyDataSetChanged();
                        bd_money = mlist.get(position).getMoney();
                        s_id = mlist.get(position).getId() + "";
                    }
                });
                btn_login.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                        CommonPopWindow.newBuilder()
                                .setView(R.layout.pop_square_detail_zhichi)
                                .setAnimationStyle(R.style.AnimUp)
                                .setBackgroundDrawable(new BitmapDrawable())
                                .setSize(0, 600)
                                .setViewOnClickListener(Square_Detail_Activity.this)
                                .setBackgroundDarkEnable(true)
                                .setBackgroundAlpha(0.7f)
                                .build(Square_Detail_Activity.this)
                                .showAsCenter(v);
                    }
                });
                break;
            case R.layout.pop_square_detail_zhichi:
                ImageView iv_pop_square_detail_cancle = view.findViewById(R.id.iv_pop_square_detail_cancle);
                TextView tv_geren_fans_cancle = view.findViewById(R.id.tv_geren_fans_cancle);
                TextView tv_geren_fans_cancle2 = view.findViewById(R.id.tv_geren_fans_cancle2);
                iv_pop_square_detail_cancle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                    }
                });
                tv_geren_fans_cancle.setText("" + bd_money.substring(0, bd_money.length()-3));
                tv_geren_fans_cancle2.setText("果冻（需消耗" + bd_money.substring(0, bd_money.length()-3) + "布丁）");
                Button btn_login1 = view.findViewById(R.id.btn_login);
                btn_login1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        JSONObject object = new JSONObject();
                        try {
                            object.put("s_id", s_id);
                            object.put("bd_money", bd_money);
                            object.put("t_uid", user_informations.get(roomId).getUid());
                            object.put("pay_psd", "");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        postZhiChi_PayData(object, v, mPopupWindow);
                    }
                });
                break;
            case R.layout.pop_geren_fans_cancle:
                TextView tv_cancle = view.findViewById(R.id.tv_cancle);
                TextView tv_geren_fans_cancle1 = view.findViewById(R.id.tv_geren_fans_cancle);
                TextView img_guanbi = view.findViewById(R.id.img_guanbi);
                tv_geren_fans_cancle1.setText("余额不足，快去充值");
                tv_cancle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                    }
                });
                img_guanbi.setText("充值");
                img_guanbi.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                        Intent intent = new Intent(Square_Detail_Activity.this, My_Wallet_Recharge_Activity.class);
                        intent.putExtra("access_token", access_token);
                        startActivity(intent);
                    }
                });
                break;
            case R.layout.pop_geren_diandian:
                TextView tv_pop_diandian_cancle = view.findViewById(R.id.tv_pop_diandian_cancle);
                tv_pop_diandian_cancle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                    }
                });
                break;
            default:
                break;
        }
    }

    /**
     * 网络请求
     */
    @SuppressLint("SetTextI18n")
    private void postData(JSONObject object) {
        Log.d("square", object.toString());
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.square_dz_list_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONObject info = jsonObject.getJSONObject("info");
                        ToolUtils.showToast(Square_Detail_Activity.this, message);//点赞成功
                        tv_geren_main_dianzan.setText("" + info.optInt("support"));
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求-获取支持列表
     */
    private void postZhiChiData() {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.square_dz_zhichi_list_Url + access_token + "&s_id=" + user_informations.get(roomId).getFiles().get(0).getS_id() + "&uid=" + user_informations.get(roomId).getUid() + "&page=1&limit=10", null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square_zc", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        List<User_Limit> user_limit = gson.fromJson(info.toString(), new TypeToken<List<User_Limit>>(){}.getType());
                        lv_xyf_jilu.setAdapter(new GeRen_Main_Fans_ListView_Adapter(Square_Detail_Activity.this, user_limit, 1, 0));
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求-获取点赞列表
     */
    private void postGetDZlistData() {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.square_dz_Url + access_token + "&s_id=" + user_informations.get(roomId).getFiles().get(0).getS_id() + "&page=1&limit=10", null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square_dz", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        List<User_Limit> user_limit = gson.fromJson(info.toString(), new TypeToken<List<User_Limit>>(){}.getType());
                        lv_xyf_jilu.setAdapter(new GeRen_Main_Fans_ListView_Adapter(Square_Detail_Activity.this, user_limit, 1, 0));
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求-发送评论消息
     */
    private void postSendPLData(JSONObject object) {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.square_send_pinglun_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square_send", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        et_chat.setText("");
                        et_chat.setHint("长得帅的都喜欢评论");
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求-获取评论列表
     */
    private void postGetPLlistData() {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.square_pinglun_Url + access_token + "&s_id=" + user_informations.get(roomId).getFiles().get(0).getS_id() + "&s_com_id=0&page=1&limit=10", null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square_pl", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        List<User_Limit> user_limit = gson.fromJson(info.toString(), new TypeToken<List<User_Limit>>(){}.getType());
                        lv_square_detail.setGroupIndicator(null);
                        //默认展开所有回复
                        CommentExpandAdapter adapter = new CommentExpandAdapter(Square_Detail_Activity.this, user_limit);
                        lv_square_detail.setAdapter(adapter);
                        for(int i = 0; i<user_limit.size(); i++){
//                            lv_square_detail.expandGroup(i);
                            to_uid = user_limit.get(i).getTo_uid();
                        }
                        lv_square_detail.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
                            @Override
                            public boolean onGroupClick(ExpandableListView expandableListView, View view, int groupPosition, long l) {
                                boolean isExpanded = expandableListView.isGroupExpanded(groupPosition);
                                if(isExpanded){
                                    expandableListView.collapseGroup(groupPosition);//监测到展开状态则收起
                                }else {
                                    expandableListView.expandGroup(groupPosition, false); //监测到收起状态则展开   第二个参数false表示展开时是否触发默认滚动动画
                                }
                                if(user_limit.get(groupPosition) == null){
                                    return true;
                                }
//                                showReplyDialog(groupPosition);
                                return true;
                            }
                        });
                        lv_square_detail.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                            @Override
                            public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition, int childPosition, long l) {
                                ToolUtils.showToast(Square_Detail_Activity.this, "点击了回复");
                                return false;
                            }
                        });
                        lv_square_detail.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
                            @Override
                            public void onGroupExpand(int groupPosition) {
                                ToolUtils.showToast(Square_Detail_Activity.this, "展开第"+groupPosition+"个分组");
                                for(int i=0; i<user_limit.size(); i++){
                                    if(groupPosition != i){
                                        lv_square_detail.collapseGroup(i);
                                    }
                                }
                            }
                        });
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求
     */
    private void postZhiChi_PayData(JSONObject object, View v, PopupWindow mpopWindow) {
        Log.d("square", object.toString());
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.square_zhichi_pay_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        ToolUtils.showToast(Square_Detail_Activity.this, message);//打赏成功
                        mpopWindow.dismiss();
                    } else if (code == 300){
                        //布丁币不足，请充值
                        CommonPopWindow.newBuilder()
                                .setView(R.layout.pop_geren_fans_cancle)
                                .setAnimationStyle(R.style.AnimUp)
                                .setBackgroundDrawable(new BitmapDrawable())
                                .setSize(0, 600)
                                .setViewOnClickListener(Square_Detail_Activity.this)
                                .setBackgroundDarkEnable(true)
                                .setBackgroundAlpha(0.7f)
                                .build(Square_Detail_Activity.this)
                                .showAsCenter(v);
                        mpopWindow.dismiss();
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求
     */
    private void postZhiChiData(View v) {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.square_zhichi_list_Url + access_token, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square_zhichi", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        mlist = gson.fromJson(info.toString(), new TypeToken<List<User_Wallet>>(){}.getType());
                        CommonPopWindow.newBuilder()
                                .setView(R.layout.pop_square_detail_pay)
                                .setAnimationStyle(R.style.AnimUp)
                                .setBackgroundDrawable(new BitmapDrawable())
                                .setSize(0, 1200)
                                .setViewOnClickListener(Square_Detail_Activity.this)
                                .setBackgroundDarkEnable(true)
                                .setOutsideTouchable(false)
                                .setBackgroundAlpha(0.7f)
                                .build(Square_Detail_Activity.this)
                                .showAsCenter(v);
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    /**
     * 网络请求
     */
    private void postUserFansData(JSONObject object, ImageView iv_square_care) {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.lt_edit_fans_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("dongtai_fans", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                        iv_square_care.setImageResource(R.mipmap.iv_ok_care);//关注成功
                    } else {
                        ToolUtils.showToast(Square_Detail_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(Square_Detail_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }
}
